layui.use(['form', 'table', 'layer', 'laydate'], function (form, table, layer, laydate) {
    form.render();
    var params = getParams();
    var mailId = parseInt(params.id);
    layer.ready(function () {
        console.log(mailId);
        $.ajax({
            url: "../email/" + mailId,
            success: function (data) {
                console.log(data);
                //给表单赋值
                form.val("sendMail_form", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                    "toMail": data.obj.toMail,
                    "title": data.obj.title,
                    "mailContent": data.obj.mailContent
                });
            }
        });
    });

    //返回 return
    $(document).on("click", "#return", function () {
        window.location.href = "inbox.html";
    });

    // 删除
    $(document).on("click", "#del", function () {
        layer.confirm('确定删除？', {icon: 3, title: '提示'}, function () {
            $.ajax({
                url: "../email/" + mailId,
                type: 'DELETE',
                success: function (data) {

                    if (data.obj) {
                        layer.msg(
                            '删除成功',
                            {
                                icon: 1,
                                time: 1000
                            },
                            function () {
                                location.href = 'inbox.html';
                            });
                    } else {
                        layer.msg('删除失败', {icon: 2});
                    }
                }
            });
        });
    });
});